using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using DataAccessLayer;
using SecurityAccessLayer;

namespace WebUI
{
    public partial class Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["UserStatus"] != null)
            {
                switch ((ValidState)Session[Keys.Session.ValidState])
                {
                    case ValidState.ConnectionFailure:
                        break;
                    case ValidState.DoesNotExist:
                        pnlNotValid.Visible = true;
                        break;
                    case ValidState.NotValid:
                        pnlNotValid.Visible = true;
                        break;
                    case ValidState.Undefined:
                        pnlNotLoggedIn.Visible = true;
                        break;
                    case ValidState.Valid:
                        switch ((LogonState)Session[Keys.Session.LogonState])
                        {
                            case LogonState.ConnectionFailure:
                                break;
                            case LogonState.DoesNotExist:
                                break;
                            case LogonState.LoggedIn:
                                if (SAL.CanUserDoStuff((int)Session[Keys.Session.UserID], DoStuffType.Manager))
                                {
                                    SetManagerFields();
                                    pnlDefaultManager.Visible = true;
                                }
                                else
                                {
                                    pnlDefaultManager.Visible = false;
                                }
                                break;
                            case LogonState.NotLoggedIn:
                                pnlNotLoggedIn.Visible = true;
                                break;
                            case LogonState.Undefined:
                                break;
                        }
                        break;
                }
            }
            else
            {
                pnlNotLoggedIn.Visible = true;
            }
        }

        private void SetManagerFields()
        {

            gvAllOpenJobs.DataSource = DAL.GetAllOpenJobs((int)Session["UserID"]);
            gvAllOpenJobs.DataBind();
        }

        protected void gvAllOpenJobs_RowEditing(object sender, GridViewEditEventArgs e)
        {
            Response.Redirect(Keys.ManagerPages.EditJob + "?JobID=" + gvAllOpenJobs.Rows[e.NewEditIndex].Cells[1].Text);
        }

        protected void btnCreateJob_Click(object sender, EventArgs e)
        {
            Response.Redirect(Keys.ManagerPages.EditJob);
        }

    }
}
